package com.lynn.springboot_demo.common;

/**
 * @Author cl
 * @Date 2020/5/11 16:29
 * 枚举
 */
public enum Color {
    RED("红色", 1),
    GREEN("绿色", 2),
    BLACK("黑色", 3),
    YELLOW("黄色", 4);
    private String name;
    private Integer index;

    //枚举构造器默认修饰符是private，也只能用private修饰构造器
    Color(String name, Integer index) {
        this.name = name;
        this.index = index;
    }

    /**
     * 获取name
     *
     * @param index
     * @return
     */
    public static String getName(int index) {
        for (Color color : Color.values()) {
            if (color.getIndex() == index) {
                return color.name;
            }
        }
        return null;
    }

    //get、set
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }
}
